<?php

require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/appconf.php');

class mapi_itrial_lookup extends Site {

    function setup() {
        $this->run_modes('list');
        $this->start_mode('list');
        parent::setup();
    }

    function cgiapp_prerun() {
        $this->Lookup = getModel('Model_Lookup');
        parent::cgiapp_prerun();
    }

    function action_list() {
        $lookup_id = intval($this->get_q('lookup_id', 0, 'int'));
        $lookup_type = $this->get_q('lookup_type');
        $lookup_list_array = array();

        $kvcobj = getCache('mapi_lookup_list', array('expire' => KVC_EXPIRE));
        $lookup_list = $kvcobj->get('mapi_lookup_list_' . $lookup_id . '_' . $lookup_type);
        if (!$lookup_list) {
            $h_param = array(
                'type' => $lookup_type,
                'id' => $lookup_id,
            );
            $lookup_list = $this->Lookup->h_get_lookup($h_param);
            $kvcobj->set('mapi_lookup_list_' . $lookup_id . '_' . $lookup_type, $lookup_list);
        }

        if ($lookup_list['result'])
            $lookup_list_array = $lookup_list['result'];
        if ($lookup_list_array) {
            $this->ajaxReturn($lookup_list_array, array('retcode' => '1', 'msg' => 'ok'));
        } else {
            $this->ajaxReturn(array(), array('retcode' => '0', 'msg' => 'not ok'));
        }
    }

}

header("Content-type: text/html; charset=utf-8");
$webapp = new mapi_itrial_lookup();
$webapp->run();
?>